import demo from './modules/demo'
import user from './modules/user'
import partition from './modules/partition'
import topic from './modules/topic'
import insulin from './modules/insulin'
import pumpSale from './modules/PumpSale'
import H5 from './modules/H5'
import center from './modules/center'
import post from './modules/post'
import TreeHole from './modules/TreeHole'
import system from './modules/system'

import layoutHeaderAside from '@/layout/header-aside'

/**
 * 在主框架内显示
 */
const frameIn = [
  {
    path: '/',
    redirect: { name: 'index' },
    component: layoutHeaderAside,
    children: [
      // 首页 必须 name:index
      {
        path: 'index',
        name: 'index',
        meta: {
          auth: true
        },
        component: () => import('@/pages/index')
      },
      // 刷新页面 必须保留
      {
        path: 'refresh',
        name: 'refresh',
        hidden: true,
        component: {
          beforeRouteEnter(to, from, next) {
            next(vm => vm.$router.replace(from.fullPath))
          },
          render: h => h()
        }
      },
      // 页面重定向 必须保留
      {
        path: 'redirect/:route*',
        name: 'redirect',
        hidden: true,
        component: {
          beforeRouteEnter(to, from, next) {
            next(vm => vm.$router.replace(JSON.parse(from.params.route)))
          },
          render: h => h()
        }
      }
    ]
  },
  demo,
  user,
  partition,
  topic,
  insulin,
  pumpSale,
  center,
  post,
  TreeHole,
  system
]

/**
 * 在主框架之外显示
 */
const frameOut = [
  // 登录
  {
    path: '/login',
    name: 'login',
    component: () => import('@/pages/login')
  },
  {
    path: '/login/confirm',
    name: 'login-confirm',
    meta: { auth: false },
    component: () => import('@/pages/login/confirm')
  },
  H5,
  {
    description: "绑定微信账号",
    path: '/account/bind',
    name: 'account-bind-wx',
    meta: { auth: false },
    component: () => import('@/pages/user/BindWechat')
  }
]

/**
 * 错误页面
 */
const errorPage = [
  // 404
  {
    path: '*',
    name: '404',
    component: () => import('@/pages/error-page-404')
  }
]

// 导出需要显示菜单的
export const frameInRoutes = frameIn

// 重新组织后导出
export default [
  ...frameIn,
  ...frameOut,
  ...errorPage
]
